package com.xquant.common.engine.xPP.request;

import com.fasterxml.jackson.annotation.JsonInclude;
import org.apache.commons.lang.StringUtils;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Ir {
    private String rate;
    private String type = "2";
    private String code;
    private CurveTS curveTS;
    private String annualDays;
    private String dayCount = "Actual/365 (Fixed)";

    public String getRate() {
        return rate;
    }

    public Ir setRate(String rate) {
        this.rate = rate;
        return this;
    }

    public String getType() {
//        当参数非code时，不能传type
        if (StringUtils.isNotEmpty(code)){
            return null;
        }
        return type;
    }

    public Ir setType(String type) {
        this.type = type;
        return this;
    }

    public String getCode() {
        return code;
    }

    public Ir setCode(String code) {
        this.code = code;
        return this;
    }

    public CurveTS getCurveTS() {
        return curveTS;
    }

    public Ir setCurveTS(CurveTS curveTS) {
        this.curveTS = curveTS;
        return this;
    }

    public String getAnnualDays() {
        return annualDays;
    }

    public Ir setAnnualDays(String annualDays) {
        this.annualDays = annualDays;
        return this;
    }

    public String getDayCount() {
        return dayCount;
    }

    public Ir setDayCount(String dayCount) {
        this.dayCount = dayCount;
        return this;
    }

    public Ir setValue(String valueType, String value, String dayCount) {
        if (StringUtils.isBlank(valueType)) {
            this.setCode(null);
            return this;
        }
        switch (valueType) {
            case "1":
                this.setCode(value);
                return this;
            default:
                this.setRate(value);
                this.setDayCount(dayCount);
                return this;
        }
    }


    public Boolean checkIrNull(){
        return StringUtils.isBlank(this.rate) && StringUtils.isBlank(this.code)
                && (this.curveTS == null || this.curveTS.getTermStructures() == null);
    }
}
